#include "Renderer/renderer.h"
#include "Renderer/renderer2D.h"
#include "Renderer/renderer3D.h"
#include "renderer.h"

namespace CC {

	Renderer::SceneData* Renderer::s_SceneData = new Renderer::SceneData();

	void Renderer::Init()
	{
		RenderCommand::Init();
		Renderer2D::Init();
		Renderer3D::Init();
	}

	void Renderer::Shutdown()
	{
		Renderer2D::Shutdown();
		Renderer3D::Shutdown();
	}

	void Renderer::OnWindowResize(uint32_t width, uint32_t height)
	{
        if (width == 0 || height == 0)
            return;
		RenderCommand::SetViewport(0, 0, width, height);
	}

	void Renderer::BeginScene(OrthographicCamera* camera)
	{
		s_SceneData->ViewProjectionMatrix = camera->GetViewProjectionMatrix();
		Renderer2D::BeginScene(camera, glm::mat4(1.0));
	}

	void Renderer::EndScene()
	{
        Renderer2D::EndScene();
	}

	void Renderer::BeginScene3D(PerspectiveCamera* camera)
	{
		CC_ASSERT(camera != nullptr, "ASSERT: Renderer::BeginScene3D camera null");
		s_SceneData->ViewProjectionMatrix = camera->GetViewProjectionMatrix();
		Renderer3D::BeginScene(camera, glm::mat4(1.0));
	}

	void Renderer::EndScene3D()
	{
        Renderer3D::EndScene();
	}

    void Renderer::SetDisplayMode(DisplayModesEnum mode)
    {
		Renderer2D::SetDisplayMode(mode);
		Renderer3D::SetDisplayMode(mode);
    }
    void Renderer::Submit(Shader *shader, const VertexArray *vertexArray, const glm::mat4 &transform, DisplayModesEnum mode)
    {
        shader->Bind();
        shader->SetMat4("u_ViewProjection", s_SceneData->ViewProjectionMatrix);
        // shader->SetMat4("u_Transform", transform);

		vertexArray->Bind();
		RenderCommand::DrawIndexed(vertexArray, mode);
	}

}
